﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace FAST
{

    /// <summary>
    /// Stores the metadata of a file.
    /// </summary>
    [Serializable()]
    public class FileHandler : FilesHandler
    {
        public string fullFilePath;
        public string subFilePath;//exclude root path
        public FileInfo fi;
        public bool dirtyBit;
        public int status;
        private bool isInOS;
        private bool isTimeConflict;
        private DateTime lastModified;
        private long fileLength;
        public int versionIdx;
        public string md5HashCode;
        private String comments;

        /// <summary>
        /// Constructor to initiate the FileHandler.
        /// </summary>
        public FileHandler()
        {
            fullFilePath = "";
            subFilePath = "";
            this.fi = null;
            this.dirtyBit = true; //default copy over
            status = (int)GUIFileStatus.FILE_NOT_EXIST;
            isInOS = false;
            isTimeConflict = false;
            setTypeFile(true);
            versionIdx = -1;
            md5HashCode = null;
            comments = "";

        }

        /// <summary>
        /// Contructor that takes in two parameters, a fullFilePath and a subFilePath.
        /// </summary>
        /// <param name="fullFilePath">Path of the root directory</param>
        /// <param name="subFilePath">Path of the file, exclude the root path</param>
        public FileHandler(string fullFilePath, string subFilePath)
        {
            this.fullFilePath = fullFilePath;
            this.subFilePath = subFilePath;
            this.fi = new FileInfo(fullFilePath);
            this.dirtyBit = true;
            this.status = (int)GUIFileStatus.FILE_NOT_EXIST;
            isInOS = false;
            isTimeConflict = false;
            setTypeFile(true);
            this.versionIdx = -1;
            this.comments = "";

            md5HashCode = null;
            this.fileLength = fi.Length;
            this.lastModified = fi.LastWriteTime;

        }

        /// <summary>
        /// Contructor that takes in five parameters, a fullFilePath, subFilePath, fi, dirtyBit, status.
        /// </summary>
        /// <param name="fullFilePath">Path of the root directory</param>
        /// <param name="subFilePath">Path of the file, exclude the root path</param>
        /// <param name="fi">File info of file</param>
        /// <param name="dirtyBit">Dirty bit of file</param>
        /// <param name="status">Status of file</param>
        public FileHandler(string fullFilePath, string subFilePath, FileInfo fi, bool dirtyBit, int status)
        {
            this.fullFilePath = fullFilePath;
            this.subFilePath = subFilePath;
            this.fi = fi;
            this.dirtyBit = dirtyBit;
            this.status = status;
            isInOS = false;
            isTimeConflict = false;
            setTypeFile(true);
            this.versionIdx = -1;
            this.comments = "";

            md5HashCode = null;
            this.fileLength = fi.Length;
            this.lastModified = fi.LastWriteTime;
           
        }

        public FileHandler(string subFilePath)
        {
            this.subFilePath = subFilePath;
            setTypeFile(true);
        }

        public void setIsInOS(bool status)
        {
            isInOS = status;
        }

        public bool isInOSCheck()
        {
            return isInOS;
        }

        public void setIsTimeConflict(bool status)
        {
            isTimeConflict = status;
        }

        public bool isTimeConflictCheck()
        {
            return isTimeConflict;
        }

        public int getFileStatus()
        {
            return this.status;
        }

        public string getSubFilePath()
        {
            return this.subFilePath;
        }

        public string getFullFilePath()
        {
            return this.fullFilePath;
        }

        public FileInfo getFi()
        {
            return this.fi;
        }
        

        public bool isDirty()
        {
            return this.dirtyBit;
        }

        public void setDirtyBit(bool dirtyBit)
        {
            this.dirtyBit = dirtyBit;
        }

        public void setFileStatus(int status)
        {
            this.status = status;
        }

        public void setSubFilePath(string subFilePath)
        {
            this.subFilePath = subFilePath;
        }

        public void setFi(FileInfo fi)
        {
            this.fi = fi;
        }

        public DateTime getLastModTime()
        {
            return this.lastModified;
        }

        public void setLastModTime(DateTime time)
        {
            this.lastModified = time;
        }

        public long getFileLength()
        {
            return this.fileLength;
        }

        public void setFileLength(long length)
        {
            this.fileLength = length;
        }

        public void setVersioningIdx(int idx)
        {
            this.versionIdx = idx;
        }

        public int getVersioningIdx()
        {
            return this.versionIdx;
        }

        public void setMd5HashCode(string md5HashCode)
        {
            this.md5HashCode = md5HashCode;
        }

        public string getMd5HashCode()
        {
            return this.md5HashCode;
        }

        public void setComments(string comments)
        {
            this.comments = comments;
        }

        public string getComments()
        {
            return comments;
        }

    }

}
